@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{{$title}}</h2>
    </div>

    <div class="cf">

        @if($method == 'getChannelRefer' && plat_identify() == 'account')
            <div class="fl">
                <a class="btn" href="javascript:;" onclick="referMember()">渠道设置</a>
            </div>
        @endif
        @if($method == 'getPersonRefer' && plat_identify() == 'account')
                <div class="fl">
                    <a class="btn" href="javascript:;" onclick="referRatio()">佣金设置</a>
                </div>
        @endif

        <div class="search-form fr cf">
            <div style="float: left;margin-right: 10px;line-height: 26px;">
                <select name="type" id="type" style="height: 30px;">
                    <option value="0" @if($type == 0) selected @endif>请选择搜索类型</option>
                    <option value="1" @if($type == 1) selected @endif>ID</option>
                    <option value="2" @if($type == 2) selected @endif>昵称</option>
                    <option value="3" @if($type == 3) selected @endif>姓名</option>
                    <option value="4" @if($type == 4) selected @endif>手机号</option>
                </select>
            </div>
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{$keyword}}"
                       placeholder="请输入对应的搜索内容">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat($ctr,$method)}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="">ID</th>
                <th class="">类型</th>
                <th class="">头像</th>
                <th class="">昵称</th>
                <th class="">姓名</th>
                <th class="">手机号</th>
                <th class="">总团队人数</th>
                <th class="">总购买桶数</th>
                <th class="">总赠送桶数</th>
                <th class="">总订单金额</th>
                <th class="">总佣金金额</th>
                <th class="">冻结金额</th>
                <th class="">已提现</th>
                <th class="">可提现</th>
                @if($method == 'getChannelRefer')<th class="">渠道码</th>@endif
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td>{{$v['id']}}</td>
                        <td>{{$v['address'] ? $v['address']['type'] == 1 ? '单位': ($v['address']['type'] == 2 ? '家庭' : '') : ''}}</td>
                        <td><img src="{{$v['avatarurl']}}" width="20px"/></td>
                        <td>{{$v['nickname']}}</td>
                        <td>{{$v['address'] ? $v['address']['name'] : ''}}</td>
                        <td>{{$v['address'] ? $v['address']['mobile'] : ''}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['total_member'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['total_buy'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['total_gift'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['total_amount'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['total_money'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['freeze_money'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['already_money'] : 0}}</td>
                        <td>{{$v['member_commission'] ? $v['member_commission']['able_money'] : 0}}</td>
                        @if($method == 'getChannelRefer')<td>{{$v['refer_code']}}</td>@endif
                        <td>
                            @if($v['refer_type'] == 2)
                                <a href="{{urlPlat($ctr,'getReferQr',['mid' => $v['id']])}}" >渠道码下载</a>
                            @endif
                            <a href="{{urlPlat($ctr,'getReferRatio',['mid' => $v['id']])}}">佣金设置</a>
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat($ctr,$method,['page'=>$v,'type'=>request('type',0),'keyword' => $keyword])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')
    <script src="/static/layer/extend/layer.ext.js"></script>
    <script type="text/javascript">
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            var type = $('#type').val();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query + '&type=' + type;
            } else {
                url += '?' + query + '&type=' + type;
            }
            window.location.href = url;
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        function referMember() {
            var url = "{{urlPlat($ctr,'getReferMemberSet')}}";
            var shop_id = "{{session('account.shop_id')}}";
            if(shop_id != null || shop_id != undefined || shop_id != 0 || shop_id != '') {
                url += '?shop_id='+shop_id;
            }
            console.log(url);
            layer.open({
                type: 2,
                title: '渠道设置',
                area: ['85%','70%'],
                fixed: false,
                content: url
            })
        }

        @if(plat_identify() == 'account')
            function referRatio() {
                var ratio = "{{isset($ratio) ? $ratio : 0}}";
                layer.prompt({
                    formType:0,
                    title:'佣金设置（当前佣金提成：'+ratio+' 元/桶）'
                }, function (val, index) {
                    var reg = /^[0-9]+.?[0-9]*$/;
                    if(reg.test(val)) {
                        $.ajax({
                            url:"{{urlPlat($ctr,'postShopReferRatio')}}",
                            data:{refer_ratio:val},
                            type:'post',
                            success:function(res){
                                if(res.status == 1) {
                                    layer.msg('设置成功')
                                    window.location.reload()
                                } else {
                                    layer.msg(res.msg)
                                }
                            },
                            fail:function () {
                                layer.msg('设置失败')
                            }
                        })
                    } else {
                        layer.msg('请输入正确的数值')
                    }
                    layer.close(index)

                })
            }
        @endif
    </script>
@endsection